import request from "@/utils/request";
import {messagePageVO, messageQuery, chatListQuery, chatListVO, chatDetailVO} from "@/api/message/types";
import {AxiosPromise} from "axios";

/**
 * 保存消息
 */
export function saveMessage(data: any) {
    return request ({
        url: '/api/v1/message/save',
        method: 'post',
        data: data
    });
}

/**
 * 获取消息列表
 * @param queryParams
 */
export function getMessageList(queryParams: messageQuery): AxiosPromise<PageResult<messagePageVO[]>>{
    return request({
        url: '/api/v1/message/query',
        method: 'get',
        params: queryParams
    });
}

/**
 * 导出消息
 * @param queryParams
 */
export function exportMessage(queryParams: any) {
    return request({
        url: '/api/v1/message/export',
        method: 'get',
        params: queryParams,
        responseType: 'arraybuffer'
    });
}

/**
 * 获取聊天会话列表
 * @param queryParams
 */
export function getChatList(queryParams: chatListQuery): AxiosPromise<PageResult<chatListVO[]>>{
    return request({
        url: '/api/v1/message/chatList',
        method: 'get',
        params: queryParams
    });
}

/**
 * 获取聊天详情
 * @param visitorId
 * @param serviceName
 * @param params 分页参数
 */
export function getChatDetail(
  visitorId: string, 
  serviceName: string,
  params: { pageNum: number; pageSize: number }
): AxiosPromise<PageResult<chatDetailVO[]>> {
  return request({
    url: `/api/v1/message/chatDetail/${visitorId}/${serviceName}`,
    method: 'get',
    params
  });
}

export function queryChatDetail(
    visitorId: string,
    params: { pageNum: number; pageSize: number }
): AxiosPromise<PageResult<chatDetailVO[]>> {
    return request({
        url: `/api/v1/message/visitorChatDetail/${visitorId}`,
        method: 'get',
        params
    });
}